package com.moyu.ui;

import javax.swing.*;
import java.awt.*;

 public abstract class Layout {

    protected int MyPanelx1;//需要放置的位置的x坐标1--框左上角
    protected int MyPanelx2;//需要放置的位置的x坐标2--框右下角
    protected int MyPanely1;//需要放置的位置的y坐标1--框左上角
    protected int MyPanely2;//需要放置的位置的x坐标2--框右下角

    protected Layout(int x, int y, int w, int h) {
        MyPanelx1 = x;
        MyPanelx2 = x+w;
        MyPanely1 = y;
        MyPanely2 = y+h;

    }

    protected  void createWindow(Graphics g) {
        Image window = new ImageIcon("resources/images/window.png").getImage();
        int size = 68;                                   //原图形中一个区块的长宽
        int GameUsesize = 8;                            //边框线的粗细
        int maxheight = window.getWidth(null); //原图形最大长宽,maxheight = 611
        //绘制窗口

        //中间填充部分
        g.drawImage(window, MyPanelx1 + GameUsesize, MyPanely1 + GameUsesize, MyPanelx2, MyPanely2, size, size, maxheight - size, maxheight - size, null);
        //左上
        g.drawImage(window, MyPanelx1, MyPanely1, MyPanelx1 + GameUsesize, MyPanely1 + GameUsesize, 0, 0, size, size, null);
        //左中
        g.drawImage(window, MyPanelx1, MyPanely1+GameUsesize, MyPanelx1 + GameUsesize, MyPanely2, 0, size, size, maxheight - size, null);
        //左下
        g.drawImage(window, MyPanelx1, MyPanely2, MyPanelx1 + GameUsesize, MyPanely2 + GameUsesize, 0, maxheight - size, size, maxheight, null);
        //中上
        g.drawImage(window, MyPanelx1 + GameUsesize, MyPanely1, MyPanelx2, MyPanely1 + GameUsesize, size, 0, maxheight - size, size, null);
        //右上
        g.drawImage(window, MyPanelx2, MyPanely1, MyPanelx2 + GameUsesize, MyPanely1 + GameUsesize, maxheight - size, 0, maxheight, size, null);
        //右中
        g.drawImage(window, MyPanelx2, MyPanely1 + GameUsesize, MyPanelx2 + GameUsesize, MyPanely2, maxheight - size, size, maxheight, maxheight - size, null);
        //右下
        g.drawImage(window, MyPanelx2, MyPanely2, MyPanelx2 + GameUsesize, MyPanely2 + GameUsesize, maxheight - size, maxheight - size, maxheight, maxheight, null);
        //中下
        g.drawImage(window, MyPanelx1 + GameUsesize, MyPanely2, MyPanelx2, MyPanely2 + GameUsesize, size, maxheight - size, maxheight - size, maxheight, null);
    }
    //抽象方法由子类实现打印
    abstract public void create(Graphics g);
}
